package server

import (
	"gitee.com/enjoy_5/coupons-rpc/internal/models"
	coupons "gitee.com/enjoy_5/coupons-rpc/proto/coupon"
)

func pointsModelList(points []models.PointsCoupon) (info []*coupons.PointsInfo) {
	for _, v := range points {
		info = append(info, &coupons.PointsInfo{
			Id:               int64(v.ID),
			CouponIntroduce:  v.CouponIntroduce,
			CouponExpiration: int64(v.CouponExpiration),
			PointsRequired:   int64(v.PointsRequired),
			CouponNumber:     int64(v.CouponNumber),
		})
	}
	return info
}

func pointsModelInfo(points *models.PointsCoupon) (info *coupons.PointsInfo) {
	return &coupons.PointsInfo{
		Id:               int64(points.ID),
		CouponIntroduce:  points.CouponIntroduce,
		CouponExpiration: int64(points.CouponExpiration),
		PointsRequired:   int64(points.PointsRequired),
		CouponNumber:     int64(points.CouponNumber),
	}
}

func PointsList() []*coupons.PointsInfo {
	m := new(models.PointsCoupon)
	pointsList, err := m.PointsList()
	if err != nil {
		return nil
	}

	return pointsModelList(pointsList)
}

func PointsInfo(id int) *coupons.PointsInfo {
	m := new(models.PointsCoupon)
	pointsInfoByID, err := m.PointsInfoByID(int64(id))
	if err != nil {
		return nil
	}
	return pointsModelInfo(pointsInfoByID)
}
